#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    int calPoints(vector<string>& operations) {
        vector<int>res;
        int n = 0;
        for (auto& o : operations) {
            if (o == "C") {
                res.pop_back();
            }
            else if (o == "D") {
                res.push_back(res.back() * 2);
            }
            else if (o == "+") {
                n = res.size();
                res.push_back(res[n - 1] + res[n - 2]);
            }
            else {
                res.push_back(stoi(o));
            }
        }
        return accumulate(res.begin(), res.end(), 0);
    }
};